package com.seguriapp.common.security;

import java.io.Serializable;
import java.util.Map;

import org.springframework.web.context.request.RequestContextHolder;

import com.google.common.collect.Maps;

public class SeguriAppSession implements Serializable {

  private static final long serialVersionUID = 3447116515472724247L;

  public enum Key {
    User, MenuLinks, LastAlertId, LastComplaintId
  }

  private String idSesion;
  private final Map<Key, Object> informacionSesion;

  protected SeguriAppSession() {
    informacionSesion = Maps.newHashMap();
  }

  public void put(final Key key, final Serializable valor) {
    informacionSesion.put(key, valor);
  }

  public Serializable get(final Key key) {
    return (Serializable) informacionSesion.get(key);
  }

  public void remove(final Key key) {
    informacionSesion.remove(key);
  }

  public String getIdSesion() {
    if (idSesion == null) {
      idSesion = RequestContextHolder.currentRequestAttributes().getSessionId();
    }
    return idSesion;
  }

}
